#include "SeqList.h"


void InitSeqList(SL* ps)
{
	assert(ps);
	ps->arr = NULL;
	ps->size = ps->capacity = 0;
}

void SLCheck(SL* ps)
{
	assert(ps);
	if (ps->size == ps->capacity)
	{
		int newcapacity = ps->capacity = 0 ? 4 : 2 * ps->capacity;
		SLData* tmp = (SLData*)realloc(ps->arr, newcapacity * sizeof(SLData));
		if (tmp == NULL)
		{
			perror("realloc fail!");
			exit(1);
		}
		ps->arr = tmp;
		ps->capacity = newcapacity;
	}

}

void SLPushBack(SL* ps,SLData x)
{
	SLCheck(ps);
	ps->arr[ps->size++] = x;
}


void SLPop(SL* ps,int x)
{
	assert(ps);
			for (int i = x; i < ps->size-1; i++)
			{
				ps->arr[i] = ps->arr[i + 1];
			}
			ps->size -= 1;
			return;
}

void SLDestroy(SL* ps)
{
	assert(ps);
	ps->arr = NULL;
	ps->capacity = ps->size = 0;
}


//void SLFind(SL ps, SLData x)
//{
//	for (int i = 0; i < ps.size; i++)
//	{
//		if (ps.arr[i] == x)
//		{
//
//		}
//	}
//}